package v3.chapter7.groupAddThread;

public class Run {

	// 线程对象关联线程组：1级关联
	public static void main(String[] args) {
		ThreadA aRunnable = new ThreadA();
		ThreadB bRunnable = new ThreadB();
		
		ThreadGroup group=new ThreadGroup("test");
		
		Thread a=new Thread(group,aRunnable);
		Thread b=new Thread(group,bRunnable);
		a.start();
		b.start();
		
		System.out.println("活动的线程数为："+group.activeCount());
		System.out.println("线程组的名称为："+group.getName());
	}
}

class ThreadA extends Thread{
	@Override
	public void run() {
		try {
			while(!Thread.currentThread().isInterrupted()) {
				System.out.println("ThreadName="+Thread.currentThread().getName());
				Thread.sleep(3000);
			}
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
}

class ThreadB extends Thread{
	@Override
	public void run() {
		try {
			while(!Thread.currentThread().isInterrupted()) {
				System.out.println("ThreadName="+Thread.currentThread().getName());
				Thread.sleep(3000);
			}
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
}